package mo.leetcode_top;

import java.util.Stack;

public class L150 {

    public int evalRPN(String[] tokens) {
        Stack<Integer> number = new Stack<>();
        for (int i = 0; i < tokens.length; i++) {
            String token = tokens[i];
            if (!token.equals("+") && !token.equals("-") && !token.equals("*") && !token.equals("/")) {
                number.push(Integer.parseInt(token));
            } else {
                int x1 = number.pop();
                int x2 = number.pop();
                switch (token) {
                    case "+":
                        number.push(x1+x2);
                        break;
                    case "-":
                        number.push(x2-x1);
                        break;
                    case "*":
                        number.push(x1*x2);
                        break;
                    case "/":
                        number.push(x2/x1);
                        break;

                }
            }
        }
        return number.pop();
    }


    public static void main(String[] args) {
        L150 test = new L150();
        System.out.println(test.evalRPN(new String[]{"10","6","9","3","+","-11","*","/","*","17","+","5","+"}));
    }
}
